package com.starleague.battletech.unit;

public abstract class AbstractWeight
        implements IWeight
{
    private static final double PRECISION = 0.000001;

    private double tons;

    protected AbstractWeight(double tons)
    {
        this.tons = tons;
    }

    protected AbstractWeight(IWeight weight)
    {
        this.tons = weight.getTons();
    }

    protected AbstractWeight()
    {
        //
    }

    @Override
    public double getTons()
    {
        return this.tons;
    }

    protected void setTons(double tons)
    {
        this.tons = tons;
    }

    @Override
    public int getTonsAsInteger()
    {
        return (int) (this.tons + PRECISION);
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        long temp;
        temp = Double.doubleToLongBits(this.tons);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof AbstractWeight))
            return false;
        AbstractWeight other = (AbstractWeight) obj;
        if (Double.doubleToLongBits(this.tons) != Double.doubleToLongBits(other.tons))
            return false;
        return true;
    }

    @Override
    public String toString()
    {
        return this.getClass().getSimpleName() + " [tons " + this.tons + "]";
    }
}
